<?php

declare(strict_types=1);

namespace app\service;

use app\utils\image\Code;
use app\utils\image\Ocr;
use thiagoalessio\TesseractOCR\TesseractOcrException;

class CodeService
{
    /**
     * 获取验证码
     *
     * @return array
     */
    public function get(): array
    {
        return Code::build();
    }

    /**
     * 验证
     *
     * @param string $key
     * @param string $code
     *
     * @return bool
     */
    public function verify(string $key, string $code): bool
    {
        return Code::verify($key, $code);
    }

    /**
     * OCR识别
     *
     * @param string $image
     *
     * @return string
     * @throws TesseractOcrException
     */
    public function ocr(string $image): string
    {
        return Ocr::handle($image);
    }
}
